1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import java.io.*;
29 import java.net.*;
30 import java.security.*;
31 import sun.applet.AppletClassLoader;
32
33 public class ClassnameCharTest implements HttpCallback {
34 private static String FNPrefix;
35 private String[] respBody = new String[52];
36 private byte[][] bufs = new byte[52][8*1024];
37 private static MessageDigest md5;
38 private static byte[] file1Mac, file2Mac;
39 public void request (HttpTransaction req) {
40 try {
41 String filename = req.getRequestURI().getPath();
42 System.out.println("getRequestURI = "+req.getRequestURI());
43 System.out.println("filename = "+filename);
44 FileInputStream fis = new FileInputStream(FNPrefix+filename);
45 req.setResponseEntityBody(fis);
46 req.sendResponse(200, "OK");
47 req.orderlyClose();
48 } catch (IOException e) {
49 e.printStackTrace();
50 }
51 }
52 static HttpServer server;
53
54 public static void test () throws Exception {
55 try {
56
57 FNPrefix = System.getProperty("test.classes", ".")+"/";
58 server = new HttpServer (new ClassnameCharTest(), 1, 10, 0);
59 System.out.println ("Server: listening on port: " + server.getLocalPort());
60 URL base = new URL("http://localhost:"+server.getLocalPort());
61 MyAppletClassLoader acl = new MyAppletClassLoader(base);
62 Class class1 = acl.findClass("fo o");
63 System.out.println("class1 = "+class1);
64
65
66
67 } catch (Exception e) {
68 if (server != null) {
69 server.terminate();
70 }
71 throw e;
72 }
73
74 server.terminate();
75 }
76
77 public static void main(String[] args) throws Exception {
78 test();
79 }
80
81 public static void except (String s) {
82 server.terminate();
83 throw new RuntimeException (s);
84 }
85 }
86
87 class MyAppletClassLoader extends AppletClassLoader {
88 MyAppletClassLoader(URL base) {
89 super(base);
90 }
91
92 public Class findClass(String name) throws ClassNotFoundException {
93 return super.findClass(name);
94 }
95 }